#!/bin/bash
#判断是否是roo用户
if [ $(id -u) != "0" ]; then
        echo "Error:You must be root to run this script"
fi

#每次使用只需修改自定义内容即可
#自定义用户名和组
Group_Name="nexus"
User_Name="nexus"

#自定义nginx变量
Install_Path="/usr/local/nexus"
Version="nexus-3.15.0-01"
Package_Type=".tar.gz"

Package=$Version$Package_Type

#创建/usr/local/nexus目录
#mkdir /usr/local/nexus
if [ -e $Install_Path ]
then
    echo " $Install_Path 目录已经存在."
    echo " $Install_Path Directory Already Exists."
else
    echo " $Install_Path 目录正在创建."
    mkdir $Install_Path
fi

#下载nexus 文件
Setup_path="/root/"
cd $Setup_path
wget https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.15.0-01-unix.tar.gz


Group_User(){
egrep "^$Group_Name" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
    echo "nexus 用户组正在添加."
    groupadd $Group_Name
else
    echo " The $Group_Name user group already exists."
    echo "nexus 用户组已经添加."
fi

#判断nexus用户是否存在
egrep "^$User_Name" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
    echo "nexus 用户正在添加."
    useradd -g $Group_Name $User_Name
else
    echo "nexus 用户已经添加."
    echo " The $User_Name user already exists."
fi
}

Group_User

# 设置/usr/local/nexus 目录所属组和用户是nexus
chown -R nexus:nexus $Install_Path

#判断文件是否存在
if [ -e $Setup_path$Version$Package_Type ]
then
        echo "$Package The Package exists."
else
        echo "$Package The package does not exist."
fi

cd $Setup_path

#解压nexus包到/usr/local/nexus
tar -zxvf $Package -C $Install_Path

echo '设置环境变量'
mv ~/.bashrc ~/.bashrc.backup.nexus
cat ~/.bashrc.backup.nexus >> ~/.bashrc
echo "NEXUS_HOME=$Install_Path/$Version" >> ~/.bashrc
echo "PATH=\"$PATH:$NEXUS_HOME/bin\"" >> ~/.bashrc

# 切换nexus用户
su nexus

echo '接下来配置：1、vim bin/nexus.rc run_as_user="nexus"'
安装完成之后，我们到/usr/local/nexus/nexus-3.15.0-01/bin目录下修改nexus文件

# 设置本地jdk目录
INSTALL4J_JAVA_HOME_OVERRIDE="/usr/local/java/jdk1.8.0_201"
接着，我们相同目录下nexus.rc文件，如下

# 指定用户是nexus而不是root，如果是root会出现警告！
run_as_user="nexus"
好了，这样就安装好了，我们访问下网站，注意默认端口是8081，账号：admin，密码：admin123


https://www.cnblogs.com/grimm/p/11404862.html